package com.ruoyi.web.controller.sports;



import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sports.domain.Advice;
import com.ruoyi.sports.service.IAdviceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * @ClassName AdviceController
 * @Description TODO
 * @Author JH Z
 * @Date 2023/3/13 16:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/advice/advice")
public class AdviceController extends BaseController
{
    @Autowired
    private IAdviceService adviceService;

    /**
     * 查询建议列表
     */
    @PreAuthorize("@ss.hasPermi('advice:advice:list')")
    @GetMapping("/list")
    public TableDataInfo list(Advice advice)
    {
        startPage();
        List<Advice> list = adviceService.selectAdviceList(advice);
        return getDataTable(list);
    }

    /**
     * 导出建议列表
     */
    @PreAuthorize("@ss.hasPermi('advice:advice:export')")
    @Log(title = "建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Advice advice)
    {
        List<Advice> list = adviceService.selectAdviceList(advice);
        ExcelUtil<Advice> util = new ExcelUtil<Advice>(Advice.class);
        util.exportExcel(response, list, "建议数据");
    }

    /**
     * 获取建议详细信息
     */
    @PreAuthorize("@ss.hasPermi('advice:advice:query')")
    @GetMapping(value = "/{adviceId}")
    public AjaxResult getInfo(@PathVariable("adviceId") Long adviceId)
    {
        return success(adviceService.selectAdviceByAdviceId(adviceId));
    }

    /**
     * 新增建议
     */
    @PreAuthorize("@ss.hasPermi('advice:advice:add')")
    @Log(title = "建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Advice advice)
    {
        return toAjax(adviceService.insertAdvice(advice));
    }

    /**
     * 修改建议
     */
    @PreAuthorize("@ss.hasPermi('advice:advice:edit')")
    @Log(title = "建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Advice advice)
    {
        return toAjax(adviceService.updateAdvice(advice));
    }

    /**
     * 删除建议
     */
    @PreAuthorize("@ss.hasPermi('advice:advice:remove')")
    @Log(title = "建议", businessType = BusinessType.DELETE)
    @DeleteMapping("/{adviceIds}")
    public AjaxResult remove(@PathVariable Long[] adviceIds)
    {
        return toAjax(adviceService.deleteAdviceByAdviceIds(adviceIds));
    }
}

